﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SCQS.Handler;

namespace SCQS.Controllers
{
    /// <summary>
    /// 查询控制器，系统主界面
    /// </summary>
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewData["Message"] = "欢迎来到防伪码查询系统!";

            return RedirectToAction("Query", "SecurityCode");
            //return View();
        }

        /*public ActionResult ChangeCode()
        {
            ViewData["ConfirmCode"] = ConfirmCode.GenCode(5);
            return View();
        }*/

        /// <summary>
        /// 验证输入的数据合法性，根据规则书写验证过程
        /// </summary>
        /// <param name="securityCode">防伪码</param>
        /// <param name="verifyCode">验证码</param>
        /// <returns></returns>
        private bool ValidateQuery(string securityCode, string verifyCode)
        {
            if (String.IsNullOrEmpty(securityCode))
            {
                ModelState.AddModelError("securityCode", "请输入防伪码");
            }
            if (String.IsNullOrEmpty(verifyCode))
            {
                ModelState.AddModelError("verifyCode", "请输入验证码");
            }
            return ModelState.IsValid;
        }

        public ActionResult Home()
        {
            //Response.Redirect("Query/Query.aspx");
            return RedirectToAction("Query", "SecurityCode");
            //return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Index(string securityCode, string verifyCode )
        {

            if (ValidateQuery(securityCode, verifyCode))
            {
                // Attempt to register the user
                /*MembershipCreateStatus createStatus = MembershipService.CreateUser(userName, password, email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuth.SignIn(userName, false);// createPersistentCookie 
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("_FORM", ErrorCodeToString(createStatus));
                }*/
                return RedirectToAction("Index", "Home");
            }

            // If we got this far, something failed, redisplay form
            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        /*[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult About()
        {
            return RedirectToAction("Query", "SecurityCode");
        }*/
    }
}
